package com.kaifamiao.month03.day0319;

import java.util.Stack;

public class Mul {

    public static void main(String[] args) {
        String str = "123456789";
        String[] s = str.split("");
        Stack<Integer> stack = new Stack<Integer>();
        createStr(s,0,s.length - 1 , stack);
    }

    public static void createStr(String[] s, int low, int high ,Stack<Integer> stack){
        if(low == high){
            calculate(s, stack);
            return;
        }
        for(int i = low; i <= high; i ++){
            String temp = s[low];
            s[low] = s[i];
            s[i] = temp;
            createStr(s, low + 1, high, stack);
            temp = s[low];
            s[low] = s[i];
            s[i] = temp;
        }
    }

    public static void calculate(String[] s ,Stack<Integer> stack){
        String nums = "";
        for (String value : s) {
            nums += value;
        }
        int n1 = Integer.parseInt(nums.substring(0,2));
        int n2 = Integer.parseInt(nums.substring(2,4));
        int n3 = Integer.parseInt(nums.substring(4,6));
        int n4 = Integer.parseInt(nums.substring(6));
        if(n1 * n2 == n3 * n4){
            if(!stack.contains(n1 * n2)){
                stack.push(n1 * n2);
                System.out.println(n1 + " x " + n2 + " = " + n3 + " x " + n4) ;
            }
        }
    }
}
